package com.zmhc.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zmhc.common.log.annotation.Log;
import com.zmhc.common.log.enums.BusinessType;
import com.zmhc.common.security.annotation.RequiresPermissions;
import com.zmhc.product.domain.DraftGoods;
import com.zmhc.product.service.IDraftGoodsService;
import com.zmhc.common.core.web.controller.BaseController;
import com.zmhc.common.core.web.domain.AjaxResult;
import com.zmhc.common.core.utils.poi.ExcelUtil;
import com.zmhc.common.core.web.page.TableDataInfo;

/**
 * 草稿商品Controller
 * 
 * @author ruoyi
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/draftGoods")
public class DraftGoodsController extends BaseController
{
    @Autowired
    private IDraftGoodsService draftGoodsService;

    /**
     * 查询草稿商品列表
     */
    @RequiresPermissions("product:draftGoods:list")
    @GetMapping("/list")
    public TableDataInfo list(DraftGoods draftGoods)
    {
        startPage();
        List<DraftGoods> list = draftGoodsService.selectDraftGoodsList(draftGoods);
        return getDataTable(list);
    }

    /**
     * 导出草稿商品列表
     */
    @RequiresPermissions("product:draftGoods:export")
    @Log(title = "草稿商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DraftGoods draftGoods)
    {
        List<DraftGoods> list = draftGoodsService.selectDraftGoodsList(draftGoods);
        ExcelUtil<DraftGoods> util = new ExcelUtil<DraftGoods>(DraftGoods.class);
        util.exportExcel(response, list, "草稿商品数据");
    }

    /**
     * 获取草稿商品详细信息
     */
    @RequiresPermissions("product:draftGoods:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(draftGoodsService.selectDraftGoodsById(id));
    }

    /**
     * 新增草稿商品
     */
    @RequiresPermissions("product:draftGoods:add")
    @Log(title = "草稿商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DraftGoods draftGoods)
    {
        return toAjax(draftGoodsService.insertDraftGoods(draftGoods));
    }

    /**
     * 修改草稿商品
     */
    @RequiresPermissions("product:draftGoods:edit")
    @Log(title = "草稿商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DraftGoods draftGoods)
    {
        return toAjax(draftGoodsService.updateDraftGoods(draftGoods));
    }

    /**
     * 删除草稿商品
     */
    @RequiresPermissions("product:draftGoods:remove")
    @Log(title = "草稿商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(draftGoodsService.deleteDraftGoodsByIds(ids));
    }
}
